package TFIDF;

import org.apache.hadoop.io.Writable;
import org.apache.hadoop.mapreduce.lib.db.DBWritable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class ResultData implements DBWritable, Writable {
    private String FilmName;
    private String word;
    private double TF;
    private double IDF;
    private double TF_IDF;

    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeUTF(FilmName);
        dataOutput.writeUTF(word);
        dataOutput.writeDouble(TF);
        dataOutput.writeDouble(IDF);
        dataOutput.writeDouble(TF_IDF);
    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {
        FilmName = dataInput.readUTF();
        word = dataInput.readUTF();
        TF = dataInput.readDouble();
        IDF = dataInput.readDouble();
        TF_IDF = dataInput.readDouble();
    }

    @Override
    public void write(PreparedStatement statement) throws SQLException {
        statement.setString(1, FilmName);
        statement.setString(2, word);
        statement.setDouble(3, TF);
        statement.setDouble(4, IDF);
        statement.setDouble(5, TF_IDF);
    }

    @Override
    public void readFields(ResultSet resultSet) throws SQLException {
        FilmName = resultSet.getString(1);
        word = resultSet.getString(2);
        TF = resultSet.getDouble(3);
        IDF = resultSet.getDouble(4);
        TF_IDF = resultSet.getDouble(5);
    }

    public void set(String filmName, String word, double TF, double IDF, double TF_IDF) {
        FilmName = filmName;
        this.word = word;
        this.TF = TF;
        this.IDF = IDF;
        this.TF_IDF = TF_IDF;
    }

    public String getFilmName() {
        return FilmName;
    }

    public void setFilmName(String filmName) {
        FilmName = filmName;
    }

    public String getWord() {
        return word;
    }

    public void setWord(String word) {
        this.word = word;
    }

    public double getTF() {
        return TF;
    }

    public void setTF(double TF) {
        this.TF = TF;
    }

    public double getIDF() {
        return IDF;
    }

    public void setIDF(double IDF) {
        this.IDF = IDF;
    }

    public double getTF_IDF() {
        return TF_IDF;
    }

    public void setTF_IDF(double TF_IDF) {
        this.TF_IDF = TF_IDF;
    }

    @Override
    public String toString() {
        return
                 FilmName + '\t' + word + '\t' + + TF +'\t' + IDF +'\t' + TF_IDF ;
    }
}
